package de.szut.hh.MVC;

import java.util.ArrayList;

class PlusMinusModel {
	private int counter;
	private int min, max;
	private ArrayList<PlusMinusListener> listeners;

	public PlusMinusModel(int _min, int _max) {
		min = _min;
		max = _max;
		counter = min;
		listeners = new ArrayList<PlusMinusListener>();
	}

	public void increment() {
		if (counter < max) {
			counter++;
			fireModelChanged();
		}
	}

	public void decrement() {
		if (counter > min) {
			counter--;
			fireModelChanged();
		}

	}
	
	public void addPlusMinusListener(PlusMinusListener l){
		listeners.add(l);
	}
	
	public void removePlusMinusListener(PlusMinusListener l){
		listeners.remove(l);
	}
	
	private void fireModelChanged() {
		// TODO Auto-generated method stub
		for (PlusMinusListener l : listeners) {
			l.valueChanged(this);
		}
	}

	public int getCounter() {
		return counter;
	}
	
	public int getMin() {
		return min;
	}
	
	public int getMax() {
		return max;
	}

}

